package pl.edu.agh.io.gpstracker.server.service.handler;

import net.customware.gwt.dispatch.server.ActionHandlerRegistry;
import net.customware.gwt.dispatch.server.ExecutionContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import pl.edu.agh.io.gpstracker.client.action.FindAllUsersAction;
import pl.edu.agh.io.gpstracker.client.dto.UserDto;
import pl.edu.agh.io.gpstracker.client.result.CollectionResult;
import pl.edu.agh.io.gpstracker.service.UserService;

import com.adeoservices.gwt.dispatch.spring.server.handler.SpringActionHandler;

/**
 * 
 * @author wkedzior
 * 
 */
@Component
public class FindAllUsersHandler extends
		SpringActionHandler<FindAllUsersAction, CollectionResult<UserDto>> {

	@Autowired
	private UserService userService;
	
	@Autowired
	public FindAllUsersHandler(ActionHandlerRegistry actionHandlerRegistry) {
		super(actionHandlerRegistry);
	}

	@Override
	public Class<FindAllUsersAction> getActionType() {
		return FindAllUsersAction.class;
	}

	@Override
	public CollectionResult<UserDto> execute(FindAllUsersAction action,
			ExecutionContext context) {
		return new CollectionResult<UserDto>(userService.findAllUsers(action.getType()));
	}

	@Override
	public void rollback(FindAllUsersAction action, CollectionResult<UserDto> result,
			ExecutionContext context) {
	}
}
